package com.crazyant;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.Log;

public class AntPers {
	
	private float x;
	private float y;
	private float tx;
	private float ty;
	
	private Ant ant;
	private String icon;
	private int rest;
	private Bitmap img;
	
	Resources resources;
	BitmapFactory.Options options;
	public Bitmap personaje;
	
	public AntPers() {
		options = new BitmapFactory.Options();
		options.inPreferredConfig = Bitmap.Config.ARGB_8888;
		resources = GV.Instancies.persview.getResources();
		
		
		ty = (float)(235);
	    tx = (float)(150);
	    //Limite de choque con el suelo
	    
		x  = (float)GV.Screen.metrics.widthPixels/2-tx/2;;
		y = (float)GV.Screen.metrics.heightPixels/2-ty/2;
		
		ant = GV.BBDD.dbhandler.getAnt(GV.BBDD.color);
		GV.Antp.id = ant.getID();
		icon = "prota"+GV.Antp.id;
		rest = resources.getIdentifier(icon, "drawable", "com.crazyant");
		img = BitmapFactory.decodeResource(resources, rest, options);
		img = Bitmap.createScaledBitmap(img,(int)tx,(int)ty,false);
	}
	
	public void update() {
		Log.d("HORMIGA ANTES DE MODFICAR ", "color"+ant.getColor()+ " cuerpo "+ant.getCuerpo());
		ant = GV.BBDD.dbhandler.getAnt(GV.Antp.color, GV.Antp.cuerpo, GV.Antp.casco, GV.Antp.botas);
		
		Log.d("HORMIGA ", "color"+ant.getColor()+ " cuerpo "+ant.getCuerpo());
		Contact contact = GV.BBDD.dbhandler.getContact(GV.BBDD.user);
		contact.setIdcolor(ant.getID());
		GV.BBDD.dbhandler.updateContact(contact);
		icon = "prota"+ant.getID();
		rest = resources.getIdentifier(icon, "drawable", "com.crazyant");
		img = BitmapFactory.decodeResource(resources, rest, options);
		img = Bitmap.createScaledBitmap(img,(int)tx,(int)ty,false);
	}
	
	
	public void onDraw(Canvas canvas) {
		canvas.drawBitmap(img, x, y, null);
	}
	
	
}
